<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Dcat\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
class Category extends Model implements Sortable
{
    use HasDateTimeFormatter,
        ModelTree{
        allNodes as treeAllNodes;
        ModelTree::boot as treeBoot;
    }

    protected $table = 'category';

    protected $titleColumn = 'name';

    protected $orderColumn = 'sort';

    protected $parentColumn = 'pid';

    public function sub()
    {
        return $this->hasMany(Category::class, 'pid', 'id')->orderBy('sort','asc');
    }

    public function parent()
    {
        return $this->hasOne(Category::class, 'id', 'pid');
    }

}
